/**
 * 
 */
package com.pmsco.pms.util;

import java.util.Random;

import com.pmsco.pms.core.constant.PmsConstant;

/**
 * @author Long Tran
 *
 */
public class PmsRandomStringGenerator {
	private static final char[] symbols = new char[36];

	static {
		for (int idx = 0; idx < 10; ++idx)
			symbols[idx] = (char) ('0' + idx);
		for (int idx = 10; idx < 36; ++idx)
			symbols[idx] = (char) ('a' + idx - 10);
	}

	private final Random random = new Random();

	private final char[] buf;

	public PmsRandomStringGenerator() {
		buf = new char[PmsConstant.defaultRandomStringLength];
	}
	
	public PmsRandomStringGenerator(int length) {
		if (length < 1)
			length = PmsConstant.defaultRandomStringLength;
		buf = new char[length];
	}

	public String nextString() {
		for (int idx = 0; idx < buf.length; ++idx) 
			buf[idx] = symbols[random.nextInt(symbols.length)];
		return new String(buf);
	}
}
